package SpotTable;

import SeqList.SeqList;
import SpotList.SpotList;

public class SpotTable implements ISpotTable {
    int len;
    SpotList data = new SpotList(len);

    @Override
    public boolean isEmpty() {
        return this.len == 0;
    }

    @Override
    public int turnName2Id(String name) {//通过景点名称获取id
        for (int i = 0; i < this.len; i++) {
            if (this.data.getName(i) == name){
                return i;
            }
        }
        return -1;
    }

    @Override
    public SeqList turnAdj2Seq(String adj) {//将adj转化为纯数字字符串
        SeqList seq = new SeqList(adj.length());
        adj.split(";");
        adj.split(",");//去除adj中所有分隔符号
        for (int i = 0; i < adj.length(); i++) {
            seq.lengthen(adj.charAt(i));
        }
        return seq;
    }

    @Override
    public int getId(int i) {
        return this.data.getId(i);
    }

    @Override
    public String getName(int i) {
        return this.data.getName(i);
    }

    @Override
    public String getIntro(int i) {
        return this.data.getIntro(i);
    }

    @Override
    public String getAdj(int i) {
        return this.data.getAdj(i);
    }

    @Override
    public void setId(int i, int id) {
        this.data.setId(i, id);
    }

    @Override
    public void setName(int i, String name) {
        this.data.setName(i, name);
    }

    @Override
    public void setIntro(int i, String intro) {
        this.data.setIntro(i, intro);
    }

    @Override
    public void setAdj(int i, String adj) {
        this.data.setAdj(i, adj);
    }

    @Override
    public void set(int i, int id, String name, String intro, String adj) {
        this.data.setId(i, id);
        this.data.setName(i, name);
        this.data.setIntro(i, intro);
        this.data.setAdj(i, adj);
    }

    @Override
    public void insert(int id, String name, String intro, String adj) {
        data.setId(this.len, id);
        data.setName(this.len, name);
        data.setIntro(this.len, intro);
        data.setAdj(this.len, adj);
        this.len++;
    }

    @Override
    public int length() {
        return 0;
    }

    @Override
    public void remove(String name) {
        for(int i = 0;i <= this.len;i++){
            if(this.data.getName(i) == name){
                for(int j = i; j < this.len - 1; j++){//把i后的数据元素依次前移
                    this.data.set(i, this.data.get(j));
                }
                this.len--;
            }
        }
        System.out.println("it's out of index.");
    }

    @Override
    public void removeAll() {
        this.len = 0;
    }

    @Override
    public SpotList getData() {
        return this.data;
    }
}
